<?php
/**
 * LilFloatBehaviorTest file
 */
App::uses('AppModel', 'Model');
App::uses('ModelBehavior', 'Model');

App::uses('LilDateBehavior', 'Lil.Model/Behavior');

/**
 * LilDateTestBehavior class
 *
 * @uses          LilDateBehavior
 * @package       lil
 * @subpackage    lil.tests.cases.model.lil_float.test
 */
class LilDateTestBehavior extends LilDateBehavior {
}
/**
 * LilFloatModel class
 *
 * @uses          AppModel
 * @package       lil
 * @subpackage    lil.tests.cases.model.lil_float.test
 */
class LilDateModel extends AppModel {
/**
* name property
*
* @var string
* @access public
*/
 	public $name = 'LilDateModel';
}

/**
 * LilFloatBehaviorTest class
 *
 * @package       lil
 * @subpackage    lil.tests.cases.libs.model.lil_float
 */
class LilDateBehaviorTest extends CakeTestCase {
/**
 * fixtures property
 *
 * @var array
 * @access public
 */
	public $fixtures = array(
		'plugin.lil.lil_date_model'
	);
/**
 * setUp method
 *
 * @access public
 * @return void
 */
	function setUp() {
		parent::setUp();
		$db = ConnectionManager::getDataSource('test');
		$db->cacheSources = false;
		$this->LilDateModel = new LilDateModel(false, null, 'test');
	}
/**
 * tearDown method
 *
 * @access public
 * @return void
 */
	function tearDown() {
		unset($this->LilDateModel);
		parent::tearDown();
	}
/**
 * testInstance method
 *
 * @access public
 * @return void
 */
	function testInstance() {
		$this->assertTrue(is_a($this->LilDateModel, 'LilDateModel'));
	}
/**
 * testLilFloatBeforeSave method
 *
 * @access public
 * @return void
 */
	function testLilDateBeforeSave() {
		Configure::write('LilFloat.dateFormat', 'DMY');
		Configure::write('LilFloat.timeFormat', '24');
		Configure::write('LilFloat.dateSeparator', '.');
		
		$result = $this->LilDateModel->Behaviors->attach('LilDateTest', array());
		$result = $this->LilDateModel->Behaviors->attached('LilDateTest');
		$this->assertTrue($result);
		
		$data['LilDateModel'] = array(
			'id'      => 1,
			'a_date' => '01.02.2010',
			'a_datetime' => '01.02.2010',
			'a_datetime_time' => array('hour' => '12', 'min' => '34'),
		);
		
		$result = $this->LilDateModel->save($data);
		$this->assertFalse(empty($result['LilDateModel']['a_date']));
		$expected = '2010-02-01';
		$this->assertEqual($result['LilDateModel']['a_date'], $expected);
		
		$this->assertFalse(empty($result['LilDateModel']['a_datetime']));
		$expected = '2010-02-01 12:34';
		$this->assertEqual($result['LilDateModel']['a_datetime'], $expected);
		
		$data['LilDateModel'] = array(
			'id'      => 1,
			'a_date' => '',
			'a_datetime' => '01.02.2010',
		);
		
		$result = $this->LilDateModel->save($data);
		$this->assertTrue(empty($result['LilDateModel']['a_date']));
		$expected = null;
		$this->assertEqual($result['LilDateModel']['a_date'], $expected);
		
		$this->assertFalse(empty($result['LilDateModel']['a_datetime']));
		$expected = '2010-02-01';
		$this->assertEqual($result['LilDateModel']['a_datetime'], $expected);
	}
/**
 * testLilFloatIsValidFloat method
 *
 * @access public
 * @return void
 */
	function testLilDateIsValidDate() {
		Configure::write('LilFloat.dateFormat', 'DMY');
		Configure::write('LilFloat.dateSeparator', '.');
		
		$result = $this->LilDateModel->Behaviors->attach('LilDateTest', array());
		$result = $this->LilDateModel->Behaviors->attached('LilDateTest');
		$this->assertTrue($result);
		
		$result = $this->LilDateModel->isValidDate(array('a_date' =>'12.10.2011'));
		$this->assertTrue($result);
	}
}